require('dotenv').config();

console.log('🔍 Google OAuth 配置验证');
console.log('================================');

// 检查环境变量
const clientId = process.env.GOOGLE_CLIENT_ID;
const clientSecret = process.env.GOOGLE_CLIENT_SECRET;
const port = process.env.PORT || 3001;

console.log(`📊 服务器端口: ${port}`);
console.log(`🔑 Google Client ID: ${clientId ? '✅ 已配置' : '❌ 未配置'}`);
console.log(`🔐 Google Client Secret: ${clientSecret ? '✅ 已配置' : '❌ 未配置'}`);

if (clientId) {
  console.log(`   Client ID (前缀): ${clientId.substring(0, 20)}...`);
  
  // 验证Client ID格式
  if (clientId.endsWith('.apps.googleusercontent.com')) {
    console.log('   ✅ Client ID 格式正确');
  } else {
    console.log('   ⚠️  Client ID 格式可能不正确，应该以 .apps.googleusercontent.com 结尾');
  }
}

console.log('\n🌐 需要在 Google Cloud Console 中配置的URL:');
console.log(`   授权的JavaScript来源: http://localhost:${port}`);
console.log(`   测试页面: http://localhost:${port}/google-auth-test.html`);
console.log(`   API端点: http://localhost:${port}/api/v1/auth/google`);

console.log('\n📝 下一步操作:');
console.log('1. 确保在 Google Cloud Console 中配置了正确的授权JavaScript来源');
console.log('2. 确保 .env 文件中配置了正确的 GOOGLE_CLIENT_ID 和 GOOGLE_CLIENT_SECRET');
console.log('3. 启动服务器: npm run dev');
console.log(`4. 访问测试页面: http://localhost:${port}/google-auth-test.html`);

if (!clientId || !clientSecret) {
  console.log('\n❌ 配置不完整，请设置环境变量后重试');
  process.exit(1);
} else {
  console.log('\n✅ 配置看起来正确');
} 